﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnLineExam.BLL;

namespace OnLineExam.Web
{
    public partial class pxStudy : System.Web.UI.Page
    {
        public OnLineExam.Model.px_Course m;
        public string filepath = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            labUser.Text = User.Identity.Name;
            if (!IsPostBack)
            {
                try
                {
                    var bll = new OnLineExam.BLL.px_Course();
                    string id = Request.QueryString["ID"];
                    if (!string.IsNullOrEmpty(id))
                    {
                        m = bll.GetModel(int.Parse(id));
                        hfPaperID.Value = m.PaperID+"";
                        var filesstr = "";
                        var files = m.c_path.Split(',');
                        if (string.IsNullOrEmpty(Request.QueryString["path"]))
                            filepath = files[0];
                        else
                        {
                            filepath = Request.QueryString["path"];
                        }
                        foreach (var item in files)
                        {
                            var dd="<li><a href='pxStudy.aspx?ID="+id+"&path="+item+"' >"+item+"</a></li>";
                            filesstr += dd;
                        }
                        Literal1.Text = filesstr;
                    }
                }
                catch (Exception)
                {
                    HHG.Common.MessageBox.ShowAndRedirect(this.Page,"发生错误，即将返回！","StudentIndex.aspx");
                    throw;
                }
                
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string id = Request.QueryString["ID"];
            var m = new OnLineExam.Model.px_UserStudayInfo();
            m.UserID = User.Identity.Name;
            m.addtime = DateTime.Now;
            m.CourseID = int.Parse(id);
            m.StudayDate = DateTime.Now;
            m.completeDate = DateTime.Now;
            var bll = new OnLineExam.BLL.px_UserStudayInfo();
            if (bll.Add(m))
                Response.Redirect("UserTest.aspx?PaperID=" + hfPaperID.Value);

        }

        protected void exit_Click(object sender, EventArgs e)
        {

        }
    }
}